package flc.ast.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.AttachPopupView;

import flc.ast.R;


public class TypeDialog extends AttachPopupView implements View.OnClickListener {

    TextView all;
    TextView type1;
    TextView type2;
    TextView type3;
    TextView type4;
    TextView type5;
    TextView type6;

    public TypeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_type;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        all = findViewById(R.id.tvMusicAll);
        type1 = findViewById(R.id.tvMusicType1);
        type2 = findViewById(R.id.tvMusicType2);
        type3 = findViewById(R.id.tvMusicType3);
        type4 = findViewById(R.id.tvMusicType4);
        type5 = findViewById(R.id.tvMusicType5);
        type6 = findViewById(R.id.tvMusicType6);


        all.setOnClickListener(this);
        type1.setOnClickListener(this);
        type2.setOnClickListener(this);
        type3.setOnClickListener(this);
        type4.setOnClickListener(this);
        type5.setOnClickListener(this);
        type6.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        clearSelection();
        switch (v.getId()) {
            case R.id.tvMusicAll:
                all.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(0);
                }
                break;
            case R.id.tvMusicType1:
                type1.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(1);
                }
                break;
            case R.id.tvMusicType2:
                type2.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(2);
                }
                break;
            case R.id.tvMusicType3:
                type3.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(3);
                }
                break;
            case R.id.tvMusicType4:
                type4.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(4);
                }
                break;
            case R.id.tvMusicType5:
                type5.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(5);
                }
                break;
            case R.id.tvMusicType6:
                type6.setTextColor(Color.parseColor("#FFFFFF"));
                dismiss();
                if (listener != null) {
                    listener.onClick(6);
                }
                break;
        }
    }

    private IListener listener;

    public void setListener(IListener listener) {
        this.listener = listener;
    }

    public interface IListener {
        void onClick(int position);

    }

    private void clearSelection() {
        all.setTextColor(Color.parseColor("#80FFFFFF"));
        type1.setTextColor(Color.parseColor("#80FFFFFF"));
        type2.setTextColor(Color.parseColor("#80FFFFFF"));
        type3.setTextColor(Color.parseColor("#80FFFFFF"));
        type4.setTextColor(Color.parseColor("#80FFFFFF"));
        type5.setTextColor(Color.parseColor("#80FFFFFF"));
        type6.setTextColor(Color.parseColor("#80FFFFFF"));
    }

}
